import axios from 'axios'
import qs from 'qs'

//import NProgress from 'nprogress'
//axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
var http=axios.create({
  //baseURL: process.env.BASE_API, // api的base_url
  timeout: 30000                  // 请求超时时间
});

export default {
    post(url, data) {
        return http({
            method: 'post',
            url,
            data: qs.stringify(data),
            timeout: 30000,
            headers: { 
                'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
            }
        }) 
    },get(url, params) {
        return http({
            method: 'get',
            url,
            params,
            timeout: 30000,
            headers: {
               
            }
        }) 
    },postJson(url, data ,responseType) {
        return http({
            responseType:responseType||'json',
            method: 'post',
            url,
            data: data,
            timeout: 30000,
            headers: { 
                'Content-Type': 'application/json;charset=utf-8'
            }
        }) 
    },
    putJson(url, data) {
        return http({
            method: 'put',
            url,
            data: data,
            timeout: 30000,
            headers: { 
                'Content-Type': 'application/json;charset=utf-8'
            }
        }) 
    },
    del:function(url){
         return http({
            method: 'delete',
            url ,
            timeout: 30000 
        }) 
    },
    put:function(url, data){
         return http({
            method: 'put',
            url,
            data: qs.stringify(data),
            timeout: 30000,
            headers: { 
                'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
            }
        }) 
    },
    patch:function(url){
         return http({
            method: 'patch',
            url ,
            timeout: 30000 
        }) 
    }
}
